<template>
    <page-main title-icon="dashboard" title="程海超   /   物理2015级   /   成都外国语学校附属小学">
        <el-row :gutter="20">
            <el-col v-for="(item,index) in graduateDetailList" :key="index+1" :lg="6" :md="8" :sm="12">
                <el-card shadow="hover" class="graduate-detail-list">
                    <router-link to="/graduateTrack/index/preview">
                        <el-image :src="item.cover" lazy fit="cover"/>
                        <div class="detail-list-content">
                            <span>{{ item.title }}</span>
                        </div>
                    </router-link>
                    <div class="detail-list-button">
                        <el-button size="mini" type="primary" @click="wordDownLoad(item.title)">下载</el-button>
                    </div>
                </el-card>
            </el-col>
        </el-row>
    </page-main>
</template>

<script>
import PageMain from '@/components/PageMain'
import axios from 'axios'

export default {
    name: 'Detail',
    components: {PageMain},
    data() {
        return {
            graduateDetailList: []
        }
    },
    mounted() {
        this.getDetailList()
    },
    methods: {
        getDetailList() {
            this.$api.get('/graduateTrack/list/detail').then(res => {
                const {list} = res
                this.graduateDetailList = list
            })
        },
        wordDownLoad(title) {
            axios({
                method: 'get',
                responseType: 'blob', // 因为是流文件，所以要指定blob类型
                url: 'http://ashuai.work:10000/getDoc' // 自己的服务器，提供的一个word下载文件接口
            }).then(({data}) => {
                const blob = new Blob([data])
                const a = document.createElement('a')
                a.href = URL.createObjectURL(blob)
                a.download = `${title}.docx`
                a.style.display = 'none'
                document.body.appendChild(a)
                a.click()
                a.remove()
            })
        }
    }
}
</script>

<style scoped lang="scss">
.graduate-detail-list {
    margin-bottom: 20px;
    cursor: pointer;
    .detail-list-content {
        padding: 14px;
        font-size: 15px;
        text-align: center;
    }
    .detail-list-button {
        position: relative;
        margin-bottom: 10px;
        button {
            position: absolute;
            right: 0;
            top: -12px;
        }
    }
}
</style>
